package com.xcity.record;

import java.sql.ResultSet;
import java.sql.SQLException;

public abstract class BaseRecord {
    protected byte status = STATUS_INSERT;
	public BaseRecord(){}
	public abstract void load(ResultSet rs) throws SQLException;
	public abstract String getColumnNames();
	public abstract String toString();
	
    public static final byte STATUS_INSERT = 0;
    public static final byte STATUS_UPDATE = 1;
    public static final byte STATUS_DROP = 2;
    public static final byte STATUS_DELETE_OLD = 3;
    public static final byte STATUS_DELETE = 4;
    public static final byte STATUS_BLANK = 5;

	public String toSqlString(){
		switch (status) {
			case STATUS_INSERT:
			{
				StringBuffer sb = new StringBuffer();
				sb.append("INSERT INTO `");
				String tableName = getClass().getSimpleName().toLowerCase();
				sb.append(tableName);
				sb.append('`');
//				sb.append(" (");
//				sb.append(getColumnNames());
//				sb.append(")");
				sb.append(" VALUES (");
				sb.append(toString());
				sb.append(");\n");
				return sb.toString();
			}
		}
		return "";
	}
}
